/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2023/2/27 20:21
 * @Version 1.0
 */
package com.eight.controller;

import com.eight.feign.CarImgFgign;
import com.eight.pojo.TbBrand;
import com.eight.service.CarBrandService;
import com.eight.vo.CarVo;
import com.eight.vo.ComResult;
import com.eight.vo.MyObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/rent/carbrand")
public class CarBrandController {

    @Autowired
    private CarBrandService carBrandService;;

    @Autowired
    private CarImgFgign carImgFgign;

    @RequestMapping("/upload/{dirPath}")
    public ComResult upload(MultipartFile file, @PathVariable String dirPath){
        return carImgFgign.upload(file,dirPath);
    }

    @RequestMapping("/list")
    public ComResult list(@RequestBody CarVo carVo) {
        if (MyObjectUtils.objectCheckIsNull(carVo)) {
        ComResult selectAllBrand = carBrandService.selectAllBrand();
        return selectAllBrand;
        }
        ComResult selectAllBrand = carBrandService.selectAllBrand(carVo);
        return selectAllBrand;
    }

    @RequestMapping("/insert")
    public ComResult insert(@RequestBody TbBrand tbBrand){
        ComResult insertBrand = carBrandService.insert(tbBrand);
        return insertBrand;
    }

    @RequestMapping("/delete")
    public ComResult delete(int id){
        ComResult deleteBrand = carBrandService.delete(id);
        return deleteBrand;
    }

    @RequestMapping("/update")
    public ComResult update(@RequestBody TbBrand tbBrand){
        ComResult updateBrand = carBrandService.update(tbBrand);
        return updateBrand;
    }

}

